import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { VantResolver } from '@vant/auto-import-resolver'
import UnoCSS from 'unocss/vite'
import { resolve } from 'path'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [VantResolver()],
    }),
    Components({
      resolvers: [VantResolver()],
    }),
    UnoCSS(),
  ],
  resolve: {
    alias: {
      // @ 替代为 src
      '@': resolve(__dirname, 'src'),
    },
    extensions: ['.vue', '.js', '.json'],
  },
  server: {
    proxy: {
      // http://127.0.0.1:5000/dev-api/content    => http://127.0.0.1:5000/content
      '/dev-api': {
        target: 'http://127.0.0.1:5000', // 后端接口
        changeOrigin: true,
        // 将 /dev-api 重写 ''
        rewrite: (path) => path.replace(/^\/dev-api/, ''),
      },
    },
  },
})
